<?php

namespace App\Models;

use App\Models\base\WarehouseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class StaffModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_staff';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    protected $guarded = [];

    //在职状态
    const ON_STATE = 1; //在职
    const OFF_STATE = 2; //离职
    const STATE_LIST = [
        self::ON_STATE => '在职',
        self::OFF_STATE => '离职',
    ];

    protected $hidden = [
        'deleted_at',
    ];

    //职位角色
    public function role(): BelongsTo {
        return $this->belongsTo(AdminRoleModel::class, 'role_id');
    }

    //创建人
    public function create_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //创建人
    public function create_user(): HasOneThrough {
        return $this->HasOneThrough(StaffModel::class, AdminModel::class, 'id', 'id', 'created_admin_id', 'staff_id');
    }


    //部门
    public function dept(): BelongsTo {
        return $this->belongsTo(DeptModel::class, 'dept_id');
    }

    //仓库
    public function warehouse(): BelongsTo {
        return $this->belongsTo(WarehouseModel::class, 'warehouse_id');
    }

}
